package cn.xfdzx.android.apps.shop.activity;


import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;


import com.alipay.sdk.app.PayTask;
import com.amap.api.maps.AMap;
import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.MapView;
import com.amap.api.maps.model.BitmapDescriptor;
import com.amap.api.maps.model.BitmapDescriptorFactory;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.MarkerOptions;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
import com.example.caller.BankABCCaller;
import com.tencent.mm.opensdk.constants.Build;
import com.tencent.mm.opensdk.modelpay.PayReq;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

import org.greenrobot.eventbus.EventBus;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;
import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.adapter.OrderDetailGoodAdapter;
import cn.xfdzx.android.apps.shop.adapter.RefundReasonAdapter;
import cn.xfdzx.android.apps.shop.adapter.SelectMapLVAdapter;
import cn.xfdzx.android.apps.shop.apps.Constants;
import cn.xfdzx.android.apps.shop.base.BaseMvpActivity;
import cn.xfdzx.android.apps.shop.bean.AfterSalesListMarketBean;
import cn.xfdzx.android.apps.shop.bean.AfterSalesListRetailBean;
import cn.xfdzx.android.apps.shop.bean.ConfirmBeen;
import cn.xfdzx.android.apps.shop.bean.ConfirmGoodBeen;
import cn.xfdzx.android.apps.shop.bean.NewOrderBeen;
import cn.xfdzx.android.apps.shop.bean.OrderListBeen;
import cn.xfdzx.android.apps.shop.bean.ReturnReasonBean;
import cn.xfdzx.android.apps.shop.contract.OrderListContract;
import cn.xfdzx.android.apps.shop.evenbus.OrderMoneyMessage;
import cn.xfdzx.android.apps.shop.evenbus.PostCarNumMessage;
import cn.xfdzx.android.apps.shop.evenbus.UpdateMyOrderMessage;
import cn.xfdzx.android.apps.shop.presenter.OrderListPresenter;
import cn.xfdzx.android.apps.shop.util.DensityUtils;
import cn.xfdzx.android.apps.shop.util.EmptyUtil;
import cn.xfdzx.android.apps.shop.util.PayResult;
import cn.xfdzx.android.apps.shop.util.ShopCarPopupWindow;
import cn.xfdzx.android.apps.shop.util.StatusBarUtil;
import cn.xfdzx.android.apps.shop.util.ToastUtil;
import cn.xfdzx.android.apps.shop.util.TransBaiduGaodePoint;
import cn.xfdzx.android.apps.shop.util.Utils;

import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
import static android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP;
import static cn.xfdzx.android.apps.shop.activity.MapDistributionActivity.drawableToBitmap;
import static cn.xfdzx.android.apps.shop.apps.Constants.WX_APP_ID;

/**
 * 零售等待支付
 */
public class WaitingPayRetailActivity extends BaseMvpActivity<OrderListPresenter> implements OrderListContract.View {

    @BindView(R.id.iv_back)
    ImageView iv_back;
    @BindView(R.id.rl_distribution_price)
    RelativeLayout rlDistributionPrice;
    @BindView(R.id.ll_distribution_information)
    LinearLayout llDistributionInformation;
    @BindView(R.id.ll_state)
    LinearLayout llState;
    @BindView(R.id.tv_contact_shop)
    TextView tvContactShop;
    @BindView(R.id.tv_distribution_price)
    TextView tvTotalFreight;
    @BindView(R.id.tv_real_pay)
    TextView tvRealPay;
    @BindView(R.id.tv_time)
    TextView tvTime;//送达时间
    @BindView(R.id.tv_address)
    TextView tvAddress;
    @BindView(R.id.tv_address_name)
    TextView tvAddressName;
    @BindView(R.id.tv_order_phone)
    TextView tvOrderPhone;
    @BindView(R.id.tv_order_time)
    TextView tvOrderTime;
    @BindView(R.id.tv_order_note)
    TextView tvOrderNote;
    @BindView(R.id.tv_address_phone)
    TextView tvAddressPhone;
    @BindView(R.id.tv_peisong_type)
    TextView tvPeisongType;
    @BindView(R.id.tv_shop_name)
    TextView tvShopName;
    @BindView(R.id.tv_cancel_order)
    TextView tvCancelOrder;
    @BindView(R.id.tv_more_pack_up)
    TextView tvMorePackUp;
    @BindView(R.id.tv_expect)
    TextView tvExpect;//倒计时
    @BindView(R.id.tv_order_title)
    TextView tvOrderTitle;//
    @BindView(R.id.tv_order_hint)
    TextView tvOrderHint;//
    @BindView(R.id.tv_to_pay)
    TextView tvToPay;//
    @BindView(R.id.tv_yi_preferential)
    TextView tvYiPreferential;//
    @BindView(R.id.tv_shop_address)
    TextView tvShopAddress;//
    @BindView(R.id.rv_goods)
    RecyclerView rvGoods;
    @BindView(R.id.tv_refund)
    TextView tv_refund;//申请售后
    @BindView(R.id.map_bg)
    View map_bg;
    @BindView(R.id.map_ziti_view)
    MapView map;
    AMap aMap;//初始化地图控制器对象

    @BindView(R.id.rl_desover)
    RelativeLayout rl_desover;//超重布局
    @BindView(R.id.tv_orerweight_fee)
    TextView tv_orerweight_fee;//超重费
    @BindView(R.id.tv_desorerweight)
    TextView tv_desorerweight;//超重费说明
    @BindView(R.id.tv_deslogic)
    TextView tv_deslogic;//基础运费
    @BindView(R.id.tv_basefee)
    TextView tv_basefee;//基础运费
    @BindView(R.id.tv_desweight)
    TextView tv_desweight;//基础重量
    private Dialog dialog;
    private ShopCarPopupWindow cancel_order_PW;
    private ShopCarPopupWindow pay_type_PW;
    private boolean is_more_pack_up = false;//收起
    private List<OrderListBeen.DataBean.CartInfoBean> list = new ArrayList<>();
    private OrderDetailGoodAdapter orderDetailGoodAdapter;
    private OrderListBeen.DataBean dataBean;
    private RelativeLayout.LayoutParams item_bar;
    private IWXAPI api;
    private ArrayList<String> selectMaps = new ArrayList<>();
    private List<String> reasonDate;
    private RecyclerView recycleReason;
    private RefundReasonAdapter refundReasonAdapter;
    private TextView tv_why_submit;//提交
    private String selReason;
    private String applyType;//申请类型1取消2售后
    private String orderId;//
    private TextView tv_reasontitle;
    private String pageposition;
    private int allcount;//所有数量
    private boolean isMore;
    private String pay_type = "weixin";
    private static final int SDK_PAY_FLAG = 1;
    private Context mContext;

    @Override
    public int getLayoutId() {
        return R.layout.activity_waiting_pay;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        map.onCreate(savedInstanceState);
    }

    @Override
    public void initView() {
        mContext = WaitingPayRetailActivity.this;
        initHigh();
        StatusBarUtil.setLightStatusBar(this, false, true);
        mPresenter = new OrderListPresenter();
        mPresenter.attachView(this);
        api = WXAPIFactory.createWXAPI(this, WX_APP_ID);
        dataBean = (OrderListBeen.DataBean) getIntent().getSerializableExtra("data");
        pay_type = dataBean.getPay_type();
        countdownTime = dataBean.getMiao();
        pageposition = getIntent().getStringExtra("pageposition");

        list.addAll(dataBean.getCartInfo());
        orderId = dataBean.getOrder_id();
        for (int i = 0; i < list.size(); i++) {
            allcount += list.get(i).getCart_num();
        }
        double totalPrice = 0;

        for (OrderListBeen.DataBean.CartInfoBean goodsBean : list) {
            totalPrice = Utils.addDouble(totalPrice, Utils.mul(Double.parseDouble(goodsBean.getMarketPrice()), goodsBean.getCart_num()));
        }
        double b = Utils.subDouble(Double.parseDouble(dataBean.getPay_price()), Double.parseDouble(dataBean.getTotal_postage()));

        totalPrice = Utils.subDouble(totalPrice, b);

        tvYiPreferential.setText("¥" + totalPrice);
        if (list.size() > 2) {
            isMore = true;
            tvMorePackUp.setVisibility(View.VISIBLE);
            tvMorePackUp.setText("共" + allcount + "件 " + getResources().getText(R.string.an_more));
            Drawable nav_up = getResources().getDrawable(R.drawable.icon_location_down);
            nav_up.setBounds(0, 0, nav_up.getMinimumWidth(), nav_up.getMinimumHeight());
        } else {
            isMore = false;
            tvMorePackUp.setVisibility(View.VISIBLE);
            tvMorePackUp.setText("共" + allcount + "件");
            tvMorePackUp.setCompoundDrawables(null, null, null, null);
        }
        String shopId="";
        if (dataBean.getCartInfo().get(0).getStore() != null) {
            shopId=dataBean.getCartInfo().get(0).getStore().getId();
        }
        orderDetailGoodAdapter = new OrderDetailGoodAdapter(this, list,shopId);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        rvGoods.setLayoutManager(linearLayoutManager);
        rvGoods.setItemAnimator(new DefaultItemAnimator());
        rvGoods.setNestedScrollingEnabled(false);
        rvGoods.setAdapter(orderDetailGoodAdapter);
        if (dataBean.getCartInfo().get(0).getStore() != null) {
            tvShopName.setText(dataBean.getCartInfo().get(0).getStore().getOffline_shop_name());
        }
        //tvTotalFreight.setText("¥" + dataBean.getTotal_postage());
        if (EmptyUtil.isNotEmpty(dataBean.getLogistics_desc())) {
            tvTotalFreight.setText("¥" + (Double.parseDouble(dataBean.getLogistics_desc().getRetail_postage()) +
                    Double.parseDouble(dataBean.getKilometre_price())));
            tv_basefee.setText("基础运费" + dataBean.getLogistics_desc().getRetail_postage() + "元");
        }
        tvRealPay.setText("实付:¥" + dataBean.getPay_price());
        tvTime.setText(dataBean.getArrive_time());
        tvAddress.setText(dataBean.getUser_address().trim());
        if (EmptyUtil.isNotEmpty(dataBean.getLogistics_desc())) {
            tv_deslogic.setText(dataBean.getLogistics_desc().getKilometre_text());
            tv_desweight.setText(dataBean.getLogistics_desc().getWeight_text());
            tv_desorerweight.setText(dataBean.getLogistics_desc().getOver_weight_price());
        }

        if (Double.parseDouble(dataBean.getWeight_price()) > 0) {
            rl_desover.setVisibility(View.VISIBLE);
            //超重费
            tv_orerweight_fee.setText("¥" + dataBean.getWeight_price());
        } else {
            rl_desover.setVisibility(View.GONE);
        }

        if (EmptyUtil.isNotEmpty(dataBean.getStore().getAddress())) {
            tvShopAddress.setText("门店地址：" + dataBean.getStore().getAddress().trim());
        } else {
            tvShopAddress.setText("门店地址：" + "(暂未获取到该店铺门店地址)");
        }

        tvAddressName.setText(dataBean.getReal_name());
        tvAddressPhone.setText(dataBean.getUser_phone() + "");
        if (dataBean.getDelivery_method() == 1) {
            tvPeisongType.setText("掌鲜配送");
            tvShopAddress.setVisibility(View.GONE);
            map.setVisibility(View.GONE);
            map_bg.setVisibility(View.GONE);
        } else if (dataBean.getDelivery_method() == 2) {
            tvPeisongType.setText("自提");
            rlDistributionPrice.setVisibility(View.GONE);
            llDistributionInformation.setVisibility(View.GONE);
            tvShopAddress.setVisibility(View.VISIBLE);
            map.setVisibility(View.VISIBLE);
            map_bg.setVisibility(View.VISIBLE);
        }
        tvOrderPhone.setText(dataBean.getOrder_id() + "");
        tvOrderTime.setText(dataBean.get_pay_time() + "");
        tvOrderNote.setText(dataBean.getMark() + "");


        if (dataBean.getPaid() == 0) {
            if (dataBean.getMiao() > 0) {
                visibility(1);
                int shi = dataBean.getMiao() / 60;
                int miao = dataBean.getMiao() - shi * 60;
                if (miao < 10) {
                    tvExpect.setText(shi + ":0" + miao);
                } else {
                    tvExpect.setText(shi + ":" + miao);
                }
                runnable.run();
            } else {
                visibility(2);
            }
        } else {
            if (dataBean.getStatus() == 0) {
                visibility(3);
            } else if (dataBean.getStatus() == 1) {
                visibility(3);
            } else if (dataBean.getStatus() == 2) {//待收货，显示取消订单按钮
                visibility(12);
            } else if (dataBean.getStatus() == 3) {//待评价，显示申请售后按钮
                visibility(13);
            } else if (dataBean.getStatus() == 4) {//已完成，显示申请售后按钮
                visibility(14);
            } else if (dataBean.getStatus() == 6) {//已售后
                visibility(16);
            } else if (dataBean.getStatus() == 7) {//已取消
                visibility(17);
            }

        }
        addMarkerInScreenCenter();


        if (new File("/data/data/com.baidu.BaiduMap").exists()) {
            selectMaps.add("com.baidu.BaiduMap");
        }
        if (new File("/data/data/com.autonavi.minimap").exists()) {
            selectMaps.add("com.autonavi.minimap");
        }
        if (new File("/data/data/com.tencent.map").exists()) {
            selectMaps.add("com.tencent.map");
        }
//支付弹窗
        payShow();

        initOnPreDrawListener();
    }

    /*
     * 方法名：initOnPreDrawListener()
     * 功    能：初始化viewTreeObserver事件监听,重写OnPreDrawListener获取组件高度
     * 参    数：无
     * 返回值：无
     */
    private void initOnPreDrawListener() {
        final ViewTreeObserver viewTreeObserver = this.getWindow().getDecorView().getViewTreeObserver();
        viewTreeObserver.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
            @Override
            public boolean onPreDraw() {
                if (getIntent().getBooleanExtra("to_pay", false)) {
                    pay_type_PW.showPopupWindow();
                }
                // 移除OnPreDrawListener事件监听
                getWindow().getDecorView().getViewTreeObserver().removeOnPreDrawListener(this);
                return true;
            }
        });
    }

    private void payShow() {
        if (pay_type_PW == null) {
            pay_type_PW = new ShopCarPopupWindow(this, R.layout.pw_pay_type);
            pay_type_PW.getRootView().findViewById(R.id.iv_back).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    pay_type_PW.shareClose();

                }
            });
            pay_type_PW.getRootView().findViewById(R.id.tv_why_submit).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    if (Utils.isFastClick()) {

                        mPresenter.toPay("routine", pay_type, dataBean.getOrder_id(), 0);
                    }
                }
            });
            pay_type_PW.getRootView().findViewById(R.id.ll_pay_weixin).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    pay_type = "weixin";
                    ((ImageView) pay_type_PW.getRootView().findViewById(R.id.iv_weixin_select)).setImageResource(R.drawable.icon_select_green);
                    ((ImageView) pay_type_PW.getRootView().findViewById(R.id.iv_zhifubao_select)).setImageResource(R.drawable.select_pay_type_grey_bg);
                    ((ImageView) pay_type_PW.getRootView().findViewById(R.id.iv_nong_hang_select)).setImageResource(R.drawable.select_pay_type_grey_bg);

                }
            });
            pay_type_PW.getRootView().findViewById(R.id.ll_pay_zhifubao).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    pay_type = "alipay";
                    ((ImageView) pay_type_PW.getRootView().findViewById(R.id.iv_weixin_select)).setImageResource(R.drawable.select_pay_type_grey_bg);
                    ((ImageView) pay_type_PW.getRootView().findViewById(R.id.iv_zhifubao_select)).setImageResource(R.drawable.icon_select_green);
                    ((ImageView) pay_type_PW.getRootView().findViewById(R.id.iv_nong_hang_select)).setImageResource(R.drawable.select_pay_type_grey_bg);
                }
            });
            pay_type_PW.getRootView().findViewById(R.id.ll_nonghang).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    pay_type = "abcp";
                    ((ImageView) pay_type_PW.getRootView().findViewById(R.id.iv_weixin_select)).setImageResource(R.drawable.select_pay_type_grey_bg);
                    ((ImageView) pay_type_PW.getRootView().findViewById(R.id.iv_zhifubao_select)).setImageResource(R.drawable.select_pay_type_grey_bg);
                    ((ImageView) pay_type_PW.getRootView().findViewById(R.id.iv_nong_hang_select)).setImageResource(R.drawable.icon_select_green);
                }
            });

            if (pay_type.equals("weixin")) {
                ((ImageView) pay_type_PW.getRootView().findViewById(R.id.iv_weixin_select)).setImageResource(R.drawable.icon_select_green);
                ((ImageView) pay_type_PW.getRootView().findViewById(R.id.iv_zhifubao_select)).setImageResource(R.drawable.select_pay_type_grey_bg);
                ((ImageView) pay_type_PW.getRootView().findViewById(R.id.iv_nong_hang_select)).setImageResource(R.drawable.select_pay_type_grey_bg);
            } else if (pay_type.equals("alipay")) {
                ((ImageView) pay_type_PW.getRootView().findViewById(R.id.iv_weixin_select)).setImageResource(R.drawable.select_pay_type_grey_bg);
                ((ImageView) pay_type_PW.getRootView().findViewById(R.id.iv_zhifubao_select)).setImageResource(R.drawable.icon_select_green);
                ((ImageView) pay_type_PW.getRootView().findViewById(R.id.iv_nong_hang_select)).setImageResource(R.drawable.select_pay_type_grey_bg);
            } else {
                ((ImageView) pay_type_PW.getRootView().findViewById(R.id.iv_weixin_select)).setImageResource(R.drawable.select_pay_type_grey_bg);
                ((ImageView) pay_type_PW.getRootView().findViewById(R.id.iv_zhifubao_select)).setImageResource(R.drawable.select_pay_type_grey_bg);
                ((ImageView) pay_type_PW.getRootView().findViewById(R.id.iv_nong_hang_select)).setImageResource(R.drawable.icon_select_green);
            }

        }


    }

    private void visibility(int i) {
        if (i == 1) {
            tvExpect.setVisibility(View.VISIBLE);
            tvToPay.setVisibility(View.VISIBLE);
            tv_refund.setVisibility(View.GONE);
            tvCancelOrder.setVisibility(View.GONE);
            map.setVisibility(View.VISIBLE);
            map_bg.setVisibility(View.VISIBLE);
            tvOrderTitle.setText("等待支付");
            tvOrderHint.setText("15分钟内未支付，订单将自动取消");
        } else if (i == 2) {
            tvExpect.setVisibility(View.GONE);
            tvToPay.setVisibility(View.GONE);
            tv_refund.setVisibility(View.GONE);
            tvCancelOrder.setVisibility(View.GONE);
            map.setVisibility(View.GONE);
            map_bg.setVisibility(View.GONE);
            tvOrderTitle.setText("已取消");
            tvOrderHint.setText("订单已取消");
        } else if (i == 3) {
            tvExpect.setVisibility(View.GONE);
            tvToPay.setVisibility(View.GONE);
            tv_refund.setVisibility(View.GONE);
            tvCancelOrder.setVisibility(View.VISIBLE);
            map.setVisibility(View.VISIBLE);
            map_bg.setVisibility(View.VISIBLE);
            tvOrderTitle.setText("已支付");
            tvOrderHint.setText("拣货中");
            if (dataBean.getDelivery_method() == 2) {
                tvOrderHint.setText("待自提");
            }
        } else if (i == 4) {
            tvExpect.setVisibility(View.GONE);
            tvToPay.setVisibility(View.GONE);
            tv_refund.setVisibility(View.GONE);
            tvCancelOrder.setVisibility(View.VISIBLE);
            map.setVisibility(View.VISIBLE);
            map_bg.setVisibility(View.VISIBLE);
            tvOrderTitle.setText("已支付");
            tvOrderHint.setText("待自提");
            if (dataBean.getDelivery_method() == 2) {
                tvOrderHint.setText("待自提");
            }
        } else if (i == 12) {//已收货待评价
            tvExpect.setVisibility(View.GONE);
            tvToPay.setVisibility(View.GONE);
            tv_refund.setVisibility(View.VISIBLE);
            tvCancelOrder.setVisibility(View.GONE);
            map.setVisibility(View.GONE);
            map_bg.setVisibility(View.GONE);
            tvOrderTitle.setText("已收货");
            tvOrderHint.setText("订单已送达");
        } else if (i == 13) {//已评价
            tvExpect.setVisibility(View.GONE);
            tvToPay.setVisibility(View.GONE);
            tv_refund.setVisibility(View.VISIBLE);
            tvCancelOrder.setVisibility(View.GONE);
            map.setVisibility(View.GONE);
            map_bg.setVisibility(View.GONE);
            tvOrderTitle.setText("已完成");
            tvOrderHint.setText("订单已完成");
        } else if (i == 14) {
            tvExpect.setVisibility(View.GONE);
            tvToPay.setVisibility(View.GONE);
            tv_refund.setVisibility(View.VISIBLE);
            tvCancelOrder.setVisibility(View.GONE);
            map.setVisibility(View.GONE);
            map_bg.setVisibility(View.GONE);
            tvOrderTitle.setText("已完成");
            tvOrderHint.setText("订单已完成");
        } else if (i == 16) {
            tvExpect.setVisibility(View.GONE);
            tvToPay.setVisibility(View.GONE);
            tv_refund.setVisibility(View.GONE);
            tvCancelOrder.setVisibility(View.GONE);
            map.setVisibility(View.GONE);
            map_bg.setVisibility(View.GONE);
            tvOrderTitle.setText("已售后");
            if (dataBean.getRefund_status() == 1) {
                if (EmptyUtil.isNotEmpty(dataBean.getRefund_type())) {
                    tvOrderHint.setText("订单处理中" + "(售后原因:" + dataBean.getRefund_type() + ")");
                } else {
                    tvOrderHint.setText("订单处理中" + "(售后原因:" + selReason + ")");
                }

            } else if (dataBean.getRefund_status() == 2) {
                tvOrderHint.setText("退款成功");
            } else if (dataBean.getRefund_status() == 3) {
                if (EmptyUtil.isNotEmpty(dataBean.getRefund_type())) {
                    tvOrderHint.setText("退款申请被驳回" + "(售后原因:" + dataBean.getRefund_type() + ")");
                } else {
                    tvOrderHint.setText("退款申请被驳回" + "(售后原因:" + selReason + ")");
                }
                tv_refund.setVisibility(View.VISIBLE);
            } else if (dataBean.getRefund_status() == 4) {
                tvOrderHint.setText("退款取消");
            }
        } else if (i == 17) {
            tvExpect.setVisibility(View.GONE);
            tvToPay.setVisibility(View.GONE);
            tv_refund.setVisibility(View.GONE);
            tvCancelOrder.setVisibility(View.GONE);
            map.setVisibility(View.GONE);
            map_bg.setVisibility(View.GONE);
            tvOrderTitle.setText("订单取消");
            if (dataBean.getRefund_status() == 5) {
                if (EmptyUtil.isNotEmpty(dataBean.getCancel_res())) {
                    tvOrderHint.setText("处理中" + "(取消原因:" + dataBean.getCancel_res() + ")");
                } else if (EmptyUtil.isNotEmpty(selReason)) {
                    tvOrderHint.setText("处理中" + "(取消原因:" + selReason + ")");
                } else {
                    tvOrderHint.setText("处理中");
                }
            } else if (dataBean.getRefund_status() == 6) {
                if (EmptyUtil.isNotEmpty(dataBean.getCancel_res())) {
                    tvOrderHint.setText("已处理" + "(取消原因:" + dataBean.getCancel_res() + ")");
                } else if (EmptyUtil.isNotEmpty(selReason)) {
                    tvOrderHint.setText("已处理" + "(取消原因:" + selReason + ")");
                } else {
                    tvOrderHint.setText("已处理");
                }
            } else if (dataBean.getRefund_status() == 7) {
                if (EmptyUtil.isNotEmpty(dataBean.getCancel_res())) {
                    tvOrderHint.setText("已驳回" + "(取消原因:" + dataBean.getCancel_res() + ")");
                } else if (EmptyUtil.isNotEmpty(selReason)) {
                    tvOrderHint.setText("已驳回" + "(取消原因:" + selReason + ")");
                } else {
                    tvOrderHint.setText("已驳回");
                }
            }
        }
    }

    int countdownTime = 15 * 60;
    Handler handler = new Handler();
    Runnable runnable = new Runnable() {
        @Override
        public void run() {

            if (dataBean.getPaid() == 0) {
                countdownTime -= 1;//倒计时总时间减1
                int cha = countdownTime;
                dataBean.setMiao(cha);
                if (cha > 0) {
                    int shi = dataBean.getMiao() / 60;
                    int mill = dataBean.getMiao() - shi * 60;
                    if (mill < 10) {
                        tvExpect.setText(shi + ":0" + mill);
                    } else {
                        tvExpect.setText(shi + ":" + mill);
                    }
                    handler.postDelayed(this, 1000);
                } else {
                    visibility(2);
                }
            }

        }
    };


    private void initHigh() {
        item_bar = (RelativeLayout.LayoutParams) llState.getLayoutParams();
        item_bar.height = StatusBarUtil.getStatusBarHeight(this);
        llState.setLayoutParams(item_bar);
    }

    @Override
    protected void onResume() {
        super.onResume();
        //在activity执行onResume时执行mMapView.onResume ()，重新绘制加载地图
        map.onResume();

        String param = getIntent().getStringExtra("from_bankabc_param");
        if (param != null) {

            param = param.substring(param.indexOf("STT="), param.length());
            String result = param.substring(4, param.indexOf("&"));
            Log.e("支付结果", "param===" + result);
            if ("0000".equals(result)) {
                //支付成功
                intent = new Intent(this, MainActivity.class);
                intent.addFlags(FLAG_ACTIVITY_CLEAR_TOP);
                intent.addFlags(FLAG_ACTIVITY_SINGLE_TOP);
                intent.putExtra("from", "pay");
                startActivity(intent);
                return;
            } else if ("9999".equals(result)) {
                Utils.toastMessage(this, "支付未完成");


            } else if ("PA500401".equals(result)) {
                Utils.toastMessage(this, "已存在成功支付的订单");
            } else {
                Utils.toastMessage(this, "支付出错");
            }

        }
    }

    @Override
    protected void onPause() {
        super.onPause();
        //在activity执行onPause时执行mMapView.onPause ()，暂停地图的绘制
        map.onPause();

    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        //在activity执行onSaveInstanceState时执行mMapView.onSaveInstanceState (outState)，保存地图当前的状态
        map.onSaveInstanceState(outState);
    }

    private void addMarkerInScreenCenter() {
        if (aMap == null) {
            aMap = map.getMap();
        }


        if (null != dataBean.getCartInfo()) {
            LatLng latLng = new LatLng(Double.parseDouble(dataBean.getCartInfo().get(0).getStore().getLat()), Double.parseDouble(dataBean.getCartInfo().get(0).getStore().getLng()));

            //设置地图的放缩级别
            aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 15));
            aMap.getUiSettings().setZoomControlsEnabled(false);
            aMap.getUiSettings().setZoomGesturesEnabled(false);
            aMap.getUiSettings().setScrollGesturesEnabled(false);
            aMap.setCustomMapStyle(
                    new com.amap.api.maps.model.CustomMapStyleOptions()
                            .setEnable(true)
                            .setStyleId("3b7df2aeffe4f90411241e09282a2cfa")//官网控制台-自定义样式 获取
            );
//            MarkerOptions markerOptions = new MarkerOptions();
//            markerOptions.position(latLng);
//            markerOptions.title(dataBean.getCartInfo().get(0).getStore().getOffline_shop_name());
//            markerOptions.snippet(dataBean.getCartInfo().get(0).getStore().getMobile());
//            markerOptions.visible(true);
//            BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.icon_shop_logo_ziti));
//            markerOptions.icon(bitmapDescriptor);
//            aMap.addMarker(markerOptions);
            RoundedCorners roundedCorners = new RoundedCorners(10);
            //通过RequestOptions扩展功能,override:采样率,因为ImageView就这么大,可以压缩图片,降低内存消耗
//        RequestOptions options = RequestOptions.bitmapTransform(roundedCorners);
            RequestOptions options = RequestOptions.bitmapTransform(roundedCorners).override(DensityUtils.dip2px(this, 44), DensityUtils.dip2px(this, 44));

            Glide.with(this)
                    .load(dataBean.getCartInfo().get(0).getStore().getLogo()).apply(options.transform(new CircleCrop(), roundedCorners)).into(new SimpleTarget<Drawable>() {
                @Override
                public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
                    Bitmap bitmap = drawableToBitmap(resource);
                    BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(bitmap);
                    aMap.addMarker(new MarkerOptions()
                            .position(latLng)
                            .icon(bitmapDescriptor));
                }
            });

//            mLocMarker.setAnchor(0.5f, 1.0f);
//            Point screenPosition = aMap.getProjection().toScreenLocation(latLng);
//            mLocMarker.setPositionByPixels(screenPosition.x, screenPosition.y);
//            mLocMarker.setPosition(latLng);
//        marker.setPosition(latLng);
        }
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void onError(Throwable throwable) {

    }

    @Override
    public void onOrderListSuccess(OrderListBeen bean) {

    }

    /**
     * 取消订单原因
     */
    @Override
    public void getRefundRreasonSuccess(ReturnReasonBean bean) {
        if (bean.getStatus() == Constants.SUCCESS_CODE) {
            reasonDate = bean.getData();
            applyType = "1";
            if (null == cancel_order_PW) {
                cancel_order_PW = new ShopCarPopupWindow(this, R.layout.pw_cancel_order_stock);
                cancel_order_PW.getRootView().findViewById(R.id.iv_back).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        cancel_order_PW.shareClose();
                    }
                });

                cancel_order_PW.getRootView().findViewById(R.id.tv_why_submit).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        if (EmptyUtil.isNotEmpty(selReason)) {
                            Map<String, Object> map = new HashMap<>();
                            map.put("orderId", orderId);
                            map.put("reason", selReason);
                            map.put("applyType", applyType);
                            mPresenter.getAfterServiceRequest(map);
                        } else {
                            Toast.makeText(mContext, "请选择原因", Toast.LENGTH_SHORT).show();
                            return;
                        }
                        cancel_order_PW.shareClose();
                    }
                });
                tv_why_submit = cancel_order_PW.getRootView().findViewById(R.id.tv_why_submit);
                recycleReason = cancel_order_PW.getRootView().findViewById(R.id.lv_cancel_order_why);
                tv_reasontitle = cancel_order_PW.getRootView().findViewById(R.id.tv_reasontitle);
                tv_reasontitle.setText("取消订单原因");
                recycleReason.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
                refundReasonAdapter = new RefundReasonAdapter(reasonDate);
                recycleReason.setAdapter(refundReasonAdapter);
                refundReasonAdapter.setItemListener(new RefundReasonAdapter.OnItemOnClickListener() {
                    @Override
                    public void onItemClick(int position, String date) {
                        selReason = date;

                        refundReasonAdapter.setItemState(position);
                        tv_why_submit.setBackgroundResource(R.drawable.shape_02c557conner5);
                    }
                });
            } else {
                refundReasonAdapter.refreshDatas(reasonDate);
            }
//            if (EmptyUtil.isNotEmpty(selReason)){
//                tv_why_submit.setBackgroundResource(R.drawable.shape_02c557conner5);
//            }else {
//                tv_why_submit.setBackgroundResource(R.drawable.e3e3e3_3);
//            }

            cancel_order_PW.showPopupWindow();
        } else {
            Toast.makeText(this, bean.getMsg(), Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void getAfterServiceRequestSuccess(ReturnReasonBean bean) {
        if (bean.getStatus() == Constants.SUCCESS_CODE) {
            Toast.makeText(this, "申请成功", Toast.LENGTH_SHORT).show();
            if (applyType.equals("1")) {
                tvOrderTitle.setText("订单取消");
                tvOrderHint.setText("取消订单处理中" + "(取消原因:" + selReason + ")");
            } else if (applyType.equals("2")) {
                tvOrderTitle.setText("已售后");
                tvOrderHint.setText("订单处理中" + "(售后原因:" + selReason + ")");
            }
            EventBus.getDefault().post(new UpdateMyOrderMessage(pageposition));

        } else {
            Toast.makeText(this, bean.getMsg(), Toast.LENGTH_SHORT).show();
        }
    }

    /**
     * 申请售后原因
     */
    @Override
    public void getReturnReasonSuccess(ReturnReasonBean bean) {
        if (bean.getStatus() == Constants.SUCCESS_CODE) {
            reasonDate = bean.getData();
            applyType = "2";
            if (null == cancel_order_PW) {
                cancel_order_PW = new ShopCarPopupWindow(this, R.layout.pw_cancel_order_stock);
                cancel_order_PW.getRootView().findViewById(R.id.iv_back).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        cancel_order_PW.shareClose();
                    }
                });
                cancel_order_PW.getRootView().findViewById(R.id.tv_why_submit).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        if (EmptyUtil.isNotEmpty(selReason)) {
                            Map<String, Object> map = new HashMap<>();
                            map.put("orderId", orderId);
                            map.put("reason", selReason);
                            map.put("applyType", applyType);
                            mPresenter.getAfterServiceRequest(map);
                        } else {
                            Toast.makeText(mContext, "请选择原因", Toast.LENGTH_SHORT).show();
                            return;
                        }
                        cancel_order_PW.shareClose();
                    }
                });
                tv_why_submit = cancel_order_PW.getRootView().findViewById(R.id.tv_why_submit);
                recycleReason = cancel_order_PW.getRootView().findViewById(R.id.lv_cancel_order_why);
                tv_reasontitle = cancel_order_PW.getRootView().findViewById(R.id.tv_reasontitle);
                tv_reasontitle.setText("申请售后原因");
                recycleReason.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
                refundReasonAdapter = new RefundReasonAdapter(reasonDate);
                recycleReason.setAdapter(refundReasonAdapter);
                refundReasonAdapter.setItemListener(new RefundReasonAdapter.OnItemOnClickListener() {
                    @Override
                    public void onItemClick(int position, String date) {
                        selReason = date;
                        refundReasonAdapter.setItemState(position);
                        tv_why_submit.setBackgroundResource(R.drawable.shape_02c557conner5);
                    }
                });
            } else {
                refundReasonAdapter.refreshDatas(reasonDate);
            }

            cancel_order_PW.showPopupWindow();
        } else {
            Toast.makeText(this, bean.getMsg(), Toast.LENGTH_SHORT).show();
        }

    }

    @Override
    public void finishRefresh() {

    }

    @Override
    public void finishLoadMore() {

    }

    @Override
    public void onPaySuccess(NewOrderBeen bean, int position) {
        if (bean.getStatus() == Constants.SUCCESS_CODE) {
            EventBus.getDefault().post(new OrderMoneyMessage(dataBean.getTotal_price(), "  "));

            if (pay_type.equals("weixin")) {
                boolean isPaySupported = api.getWXAppSupportAPI() >= Build.PAY_SUPPORTED_SDK_INT;
                if (isPaySupported) {
                    PayReq req = new PayReq();
                    req.appId = bean.getData().getResult().getJsConfig().getAppid();
                    req.partnerId = bean.getData().getResult().getJsConfig().getPartnerid();
                    req.prepayId = bean.getData().getResult().getJsConfig().getPrepayid();
                    req.nonceStr = bean.getData().getResult().getJsConfig().getNoncestr();
                    req.timeStamp = bean.getData().getResult().getJsConfig().getTimestamp() + "";
                    req.packageValue = bean.getData().getResult().getJsConfig().getPackageX();
                    req.sign = bean.getData().getResult().getJsConfig().getSign();
                    req.extData = "";
                    api.sendReq(req);
                } else {
                    Toast.makeText(this, "当前微信版本不支持支付", Toast.LENGTH_SHORT).show();
                }
            } else if (pay_type.equals("alipay")) {
                final Runnable payRunnable = new Runnable() {

                    @Override
                    public void run() {
                        PayTask alipay = new PayTask(WaitingPayRetailActivity.this);
                        Map<String, String> result = alipay.payV2(bean.getData().getResult().getAlipay_param(), true);
                        Log.i("msp", result.toString());

                        Message msg = new Message();
                        msg.what = SDK_PAY_FLAG;
                        msg.obj = result;
                        mHandler.sendMessage(msg);
                    }
                };

                // 必须异步调用
                Thread payThread = new Thread(payRunnable);
                payThread.start();
            } else {
/**
 * 判断手机上是否具备调起农行掌银的条件
 */
                if (BankABCCaller.isBankABCAvaiable(WaitingPayRetailActivity.this)) {
                    /**
                     * 调起农行掌银
                     */
//                    BankABCCaller.startBankABC(ConfirmOrderActivity.this, "cn.xfdzx.android.apps.shop", "cn.xfdzx.android.apps.shop.activity.ConfirmOrderActivity", "pay", bean.getData().getResult().getAbcApp());
                    BankABCCaller.startBankABC(WaitingPayRetailActivity.this, "cn.xfdzx.android.apps.shop", "cn.xfdzx.android.apps.shop.activity.WaitingPayRetailActivity", "pay", bean.getData().getResult().getAbcApp());
                } else {//客户手机未安装农行掌银APP的处理逻辑，由第三方APP自行实现
                    Toast.makeText(WaitingPayRetailActivity.this, "没安装农行掌银，或已安装农行掌银版本不支持", Toast.LENGTH_LONG).show();
                }
                return;
            }

        } else {
            Toast.makeText(this, bean.getMsg(), Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void onConfirmSuccess(ConfirmBeen bean, int position) {

    }

    @Override
    public void onGetAfterSalesRetailListSuccess(AfterSalesListRetailBean bean) {

    }

    @Override
    public void onGetIsExceedTimeSuccess(AfterSalesListRetailBean bean) {
        if (bean.getStatus() == Constants.SUCCESS_CODE) {
            Intent intentrefund = new Intent(mContext, AfterServiceReturnMoneyActivity.class);
            intentrefund.putExtra("type", "0");
            intentrefund.putExtra("orderid", orderId);
            mContext.startActivity(intentrefund);
        }else {
            Toast.makeText(this, bean.getMsg(), Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void onGetAfterSalesMarketListSuccess(AfterSalesListMarketBean bean) {

    }

    private ShopCarPopupWindow select_Map_PW;

    @OnClick({R.id.tv_shop_name, R.id.map_bg, R.id.tv_more_pack_up, R.id.tv_contact_shop, R.id.iv_lianxi, R.id.tv_cancel_order, R.id.tv_to_pay,
            R.id.tv_fuzhi, R.id.iv_back, R.id.tv_refund})
    public void OnClick(View view) {
        switch (view.getId()) {
            case R.id.tv_shop_name:
                Intent intent = new Intent(this, ShopActivity.class);
                intent.putExtra("shop_id", dataBean.getStore().getId() + "");
                startActivity(intent);
                break;
            case R.id.map_bg:
                if (selectMaps.size() == 0) {

                    return;
                }
                if (select_Map_PW == null) {
                    select_Map_PW = new ShopCarPopupWindow(this, R.layout.pw_select_map);
                    SelectMapLVAdapter selectMapLVAdapter = new SelectMapLVAdapter(this, selectMaps);

                    ((ListView) select_Map_PW.getRootView().findViewById(R.id.lv_map)).setAdapter(selectMapLVAdapter);
                    ((ListView) select_Map_PW.getRootView().findViewById(R.id.lv_map)).setOnItemClickListener(new AdapterView.OnItemClickListener() {
                        @Override
                        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                            select_Map_PW.shareClose();
                            if ("com.baidu.BaiduMap".equals(selectMaps.get(position))) {

                                LatLng sourceLatLng = new LatLng(Double.parseDouble(dataBean.getCartInfo().get(0).getStore().getLat()), Double.parseDouble(dataBean.getCartInfo().get(0).getStore().getLng()));

                                LatLng desLatLng = TransBaiduGaodePoint.gaode_to_baidu(sourceLatLng);
                                Intent intent = new Intent("android.intent.action.VIEW", android.net.Uri.parse("baidumap://map/geocoder?location=" + desLatLng.latitude + "," + desLatLng.longitude));
                                startActivity(intent);
                            } else if ("com.autonavi.minimap".equals(selectMaps.get(position))) {
                                Intent intent = new Intent("android.intent.action.VIEW", android.net.Uri.parse("androidamap://route?sourceApplication=appName&slat=&slon=&sname=我的位置&dlat=" + dataBean.getCartInfo().get(0).getStore().getLat() + "&dlon=" + dataBean.getCartInfo().get(0).getStore().getLng() + "&dname=目的地&dev=0&t=2"));
                                startActivity(intent);
                            } else if ("com.tencent.map".equals(selectMaps.get(position))) {
                                Intent intent = new Intent("android.intent.action.VIEW", android.net.Uri.parse("qqmap://map/routeplan?type=drive&from=&fromcoord=&to=目的地&tocoord=" + dataBean.getCartInfo().get(0).getStore().getLat() + "," + dataBean.getCartInfo().get(0).getStore().getLng() + "&policy=0&referer=appName"));
                                startActivity(intent);
                            }

                        }
                    });
                }
                select_Map_PW.showPopupWindow();
                break;
            case R.id.tv_more_pack_up:
                if (!isMore) {
                    return;
                }
                if (Utils.isFastClick()) {
                    if (is_more_pack_up) {
                        orderDetailGoodAdapter.is_open = false;
                        orderDetailGoodAdapter.notifyDataSetChanged();
                        tvMorePackUp.setText("共" + allcount + "件 " + getResources().getText(R.string.an_more));
                        Drawable nav_up = getResources().getDrawable(R.drawable.icon_confirm_order_more);
                        nav_up.setBounds(0, 0, nav_up.getMinimumWidth(), nav_up.getMinimumHeight());
                        tvMorePackUp.setCompoundDrawables(null, null, nav_up, null);

                    } else {
                        orderDetailGoodAdapter.is_open = true;
                        orderDetailGoodAdapter.notifyDataSetChanged();
                        tvMorePackUp.setText("共" + allcount + "件 " + getResources().getText(R.string.pack_up));
                        Drawable nav_up = getResources().getDrawable(R.drawable.icon_location_on);
                        nav_up.setBounds(0, 0, nav_up.getMinimumWidth(), nav_up.getMinimumHeight());

                        tvMorePackUp.setCompoundDrawables(null, null, nav_up, null);

                    }
                    is_more_pack_up = !is_more_pack_up;
                }
                break;
            case R.id.iv_lianxi:
            case R.id.tv_contact_shop:
                if (Utils.isFastClick()) {
                    dialog = Utils.addDialog(this, R.layout.dialog, "15810103429", R.string.call, new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            if (Utils.isFastClick()) {
                                dialog.dismiss();
                                Intent intent = new Intent(Intent.ACTION_DIAL);
                                Uri data = Uri.parse("tel:" + "15810103429");
                                intent.setData(data);
                                startActivity(intent);
                            }
                        }
                    });
                    dialog.show();
                }
                break;
            case R.id.tv_cancel_order:
                if (Utils.isFastClick()) {
                    mPresenter.getRefundRreason();
                }
//                if (Utils.isFastClick()){
//                if (cancel_order_PW != null) {
//
//                } else {
//                    cancel_order_PW = new ShopCarPopupWindow(this, R.layout.pw_cancel_order_stock);
//                    cancel_order_PW.getRootView().findViewById(R.id.iv_back).setOnClickListener(new View.OnClickListener() {
//                        @Override
//                        public void onClick(View view) {
//                            cancel_order_PW.shareClose();
//                        }
//                    });
//
//                    ((ListView) cancel_order_PW.getRootView().findViewById(R.id.lv_cancel_order_why)).setAdapter(new CancelOrderWhyLVAdapter(this, new ArrayList<String>()));
//                }
//                cancel_order_PW.showPopupWindow();}
                break;
            case R.id.tv_to_pay:

                pay_type_PW.showPopupWindow();
                break;
            case R.id.tv_fuzhi:
                Utils.copy(this, tvOrderPhone.getText().toString());
                Toast.makeText(this, "复制成功", Toast.LENGTH_SHORT).show();
                break;
            case R.id.iv_back:
                finish();
                break;
            case R.id.tv_refund://申请售后
                Log.e("tv_refund", "tv_refund");
                if (Utils.isFastClick()) {
                    //请求判断是否超过24小时
                    mPresenter.getIsExceedTime(orderId);

                }
                break;

        }
    }

    @Override
    protected boolean isUseFullScreenMode() {
        return true;
    }


    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);

    }


    @Override
    protected void onDestroy() {
        selectMaps.clear();
        if (null != dialog) {
            if (dialog.isShowing()) {
                dialog.dismiss();
            }
            dialog = null;
        }
        if (null != cancel_order_PW) {
            if (cancel_order_PW.isShowing()) {
                cancel_order_PW.dismiss();
            }
            cancel_order_PW = null;
        }
        if (null != pay_type_PW) {
            if (pay_type_PW.isShowing()) {
                pay_type_PW.dismiss();
            }
            pay_type_PW = null;
        }

        handler.removeCallbacksAndMessages(null);

        super.onDestroy();
    }

    @Override
    public void onBackPressed() {
        if (null != dialog) {
            if (dialog.isShowing()) {
                dialog.dismiss();
                return;
            }

        }
        if (null != cancel_order_PW) {
            if (cancel_order_PW.isShowing()) {
                cancel_order_PW.shareClose();
                return;
            }

        }
        if (null != pay_type_PW) {
            if (pay_type_PW.isShowing()) {
                pay_type_PW.shareClose();
                return;
            }

        }
        super.onBackPressed();
    }


    Intent intent;
    @SuppressLint("HandlerLeak")
    private Handler mHandler = new Handler() {
        @SuppressWarnings("unused")
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case SDK_PAY_FLAG: {
                    @SuppressWarnings("unchecked")
                    PayResult payResult = new PayResult((Map<String, String>) msg.obj);
                    /**
                     * 对于支付结果，请商户依赖服务端的异步通知结果。同步通知结果，仅作为支付结束的通知。
                     */
                    String resultInfo = payResult.getResult();// 同步返回需要验证的信息
                    String resultStatus = payResult.getResultStatus();

                    // 判断resultStatus 为9000则代表支付成功
                    if (TextUtils.equals(resultStatus, "9000")) {
                        // 该笔订单是否真实支付成功，需要依赖服务端的异步通知。

                        intent = new Intent(mContext, MainActivity.class);
                        intent.addFlags(FLAG_ACTIVITY_CLEAR_TOP);
                        intent.addFlags(FLAG_ACTIVITY_SINGLE_TOP);
                        intent.putExtra("from", "pay");
                        startActivity(intent);
                        break;
                    } else {
                        // 该笔订单真实的支付结果，需要依赖服务端的异步通知。

                        intent = new Intent(mContext, MainActivity.class);
                        intent.addFlags(FLAG_ACTIVITY_CLEAR_TOP);
                        intent.addFlags(FLAG_ACTIVITY_SINGLE_TOP);
                        intent.putExtra("from", "pay_cancel");
                        startActivity(intent);


                    }

                    break;
                }

                default:
                    break;
            }
        }

        ;
    };

}
